package com.zsummer.design.create.abstractfactory;

/**
 * @author zsummer
 * 2020/3/22 10:51
 * 抽象工厂
 */
public class Client {
    public static void main(String[] args) {
        PetFactory catFactory = new CatFactory();
        Pet cat = catFactory.getPet();
        cat.show();
        Food fish = catFactory.getFood();
        fish.show();
    }
}

abstract class Pet {
    abstract void show();
}

class Cat extends Pet {

    @Override
    void show() {
        System.out.println("a cat");
    }
}

abstract class Food {
    abstract void show();
}

class Fish extends Food {

    @Override
    void show() {
        System.out.println("a fish");
    }
}

abstract class PetFactory {
    abstract Pet getPet();
    abstract Food getFood();
}

class CatFactory extends PetFactory {

    @Override
    Pet getPet() {
        return new Cat();
    }

    @Override
    Food getFood() {
        return new Fish();
    }
}
